from django.db import models


class FrontUser(models.Model):
    u_name = models.CharField(max_length=30, help_text='用户昵称')
    name = models.CharField(max_length=30, help_text='用户姓名')
    create_time = models.DateTimeField(auto_now_add=True, help_text='创建时间')
    update_time = models.DateTimeField(auto_now=True, help_text='更新时间')

    class Meta:
        db_table = 'front_user'
        ordering = (
            '-create_time',
            '-id'
        )

    def __str__(self):
        return f'<FrontUser:({self.pk}, {self.name})>'

    __repr__ = __str__


class FrontUserExtension(models.Model):
    birthday = models.DateField(help_text='生日')
    address = models.CharField(max_length=150, help_text='用户地址')
    create_time = models.DateTimeField(auto_now_add=True, help_text='创建时间')
    update_time = models.DateTimeField(auto_now=True, help_text='更新时间')
    # 一对一关系
    user = models.OneToOneField('FrontUser', on_delete=models.CASCADE, related_name='extension')

    class Meta:
        db_table = 'front_user_extension'
        ordering = (
            '-create_time',
            '-id'
        )

    def __str__(self):
        return f'<FrontUserExtension:({self.pk}, {self.user.name}, {self.birthday}, {self.address})>'

    __repr__ = __str__
